<template>
<div class="jujia">
  <div class="top">
    <header>
      <div class="div" @click="back">
        <img src="../../../assets/返回.png" alt="">
        <span class="solid">返回</span>
      </div>
      <div class="search">
        <van-icon name="search" class="search_img" />
        <input type="text"
               v-model="searchVal"
               :placeholder="select === 1 ? '项目名称' : select === 2 ? '团队名称' :'请输入'">
        <van-icon name="close"
                  v-show="searchVal"
                  class="close_img" @click="searchVal = ''" />
      </div>
    </header>
    <div class='tabBar'>
      <router-link @click.native="searchXiangmu"
                   :to="{path:'/JuJia/JuJiaXiangmu',
      query: {userid: this.userid, team_id: this.team_id,searchVal:searchVal, type: type}}"
                   replace
                   class='tab' :class="{'act':select===1}" >
        项目
        <p class='line'></p>
      </router-link>
      <router-link
        @click.native="searchTeam"
        :to="{path: '/JuJia/TeamJuJia', query: {userid: this.userid, team_id: this.team_id,
        type: type,
        searchVal:searchVal}}"
                   replace
                   class='tab' :class="{'act':select===2}" >
        团队
        <p class='line'></p>
      </router-link>
    </div>
  </div>
  <router-view />
</div>
</template>

<script>
export default {
  name: 'JuJia',
  data () {
    return {
      userid: this.$route.query.userid,
      team_id: this.$route.query.team_id,
      type: this.$route.query.type,
      select: 1,
      searchVal: ''
    }
  },
  mounted () {
    sessionStorage.removeItem('serviceJuJia')  // 移除服务详情
    if (this.$route.query.searchVal) {
      this.searchVal = this.$route.query.searchVal
    }
    this.$route.name === 'JuJiaXiangmu' ? this.select = 1 : this.select = 2
  },
  watch: {
    searchVal (val1, val2) {
      if (val1 !== val2) {
        if (this.select === 1) {
          this.searchXiangmu()
        } else {
          this.searchTeam()
        }
      }
    }
  },
  methods: {
    searchXiangmu () {
      this.select = 1
      this.$router.replace({path: '/JuJia/JuJiaXiangmu', query: {userid: this.userid, team_id: this.team_id, searchVal: this.searchVal, type: this.type}})
    },
    searchTeam () {
      this.select = 2
      this.$router.replace({path: '/JuJia/TeamJuJia', query: {userid: this.userid, team_id: this.team_id, searchVal: this.searchVal, type: this.type}})
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    }
  }
}
</script>

<style scoped lang="scss">
.jujia{
  width: 100%;
  height: 100%;
  background: #FAF9FE;
  overflow: auto;
  font-size: 15px;
  font-family: PingFang SC;
}
.top{
  position: sticky;
  top: 0;
  z-index: 9;
}
header{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #E5E5E5;
  background: white;
  padding: 0 15px;
  box-sizing: border-box;
}
.div{
  height: 100%;
  display: flex;
  align-items: center;
  font-family: "PingFang SC";
  font-size: 15px;
  font-weight: bold;
}
.div:nth-child(1) img{
  height: 13px;
  width: 7px;
  margin-right: 5px;
}
.solid{
  color: #1DA4F2;
}
.search{
  width: 75%;
  //border: 1px solid #E5E5E5;
  margin-left: 10px;
  height: 29px;
  background: #FAF9FE;
  border-radius: 15px;
  display: flex;
  align-items: center;
  overflow: hidden;
  .search_img{
    font-size: 17px;
    padding: 0 5px;
    box-sizing: border-box;
  }
  input{
    flex: 1;
    overflow: auto;
    border: none;
    background: transparent;
  }
  .close_img{
    font-size: 13px;
    padding: 0 5px;
    box-sizing: border-box;
  }
}
.tabBar {
  width: 100%;
  height: 44px;
  overflow: hidden;
  background-color: white;

  .tab {
    width: 50%;
    float: left;
    font-size: 15px;
    color: #333333;
    line-height: 44px;
    text-align: center;
    position: relative;

    .line {
      display: none;
      width: 25px;
      height: 2px;
      border-radius: 1px;
      background-color: #1DA4F2;
      position: absolute;
      left: 50%;
      bottom: 5px;
      transform: translateX(-50%);
    }

    &.act {
      color: #1DA4F2;

      .line {
        display: block;
      }
    }
  }
}
</style>
